home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / gencodec / source / hook_utility.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  1KB  |  61 lines

  1. #include "Hook_Utility.h"
  2.  
  3. #ifdef __GNUC__
  4.  
  5. static APTR Function_Hook(void)
  6. {
  7.     register struct Hook *a0 __asm("a0");
  8.     register APTR a2 __asm("a2");
  9.     register APTR a1 __asm("a1");
  10.     register APTR a4 __asm("a4");
  11.     
  12.     a4=(APTR)a0->h_MinNode.mln_Succ;
  13.  
  14.     return ((proto_c_function)a0->h_SubEntry)(a0,a2,a1);
  15. }
  16.  
  17. void InstallHook(struct Hook *hook, proto_c_function c_function, APTR Data)
  18. {
  19.     register APTR a4 __asm("a4");
  20.     struct MinNode null_node;
  21.     
  22.     null_node.mln_Succ=(struct MinNode*)a4;
  23.     null_node.mln_Pred=NULL;
  24.  
  25.     hook->h_MinNode = null_node;
  26.     hook->h_Entry = (ULONG (*)()) Function_Hook;
  27.     hook->h_SubEntry = (ULONG (*)())c_function;
  28.     hook->h_Data = Data;
  29. }
  30.  
  31. #else
  32.  
  33. #include <dos.h>
  34.  
  35. static APTR __asm Function_Hook(register __a0 struct Hook *hook,
  36.                                   register __a2 APTR        object,
  37.                                   register __a1 APTR        message)
  38. {
  39.     putreg(REG_A4,(long)hook->h_MinNode.mln_Succ);
  40.     
  41.     return(((proto_c_function)hook->h_SubEntry)(hook,object,message));
  42. }
  43.  
  44. void InstallHook(struct Hook *hook, proto_c_function c_function, APTR Data)
  45. {
  46.     struct MinNode null_node;
  47.     
  48.     null_node.mln_Succ=(struct MinNode*)getreg(REG_A4);
  49.     null_node.mln_Pred=NULL;
  50.  
  51.     hook->h_MinNode = null_node;
  52.     hook->h_Entry = (ULONG (*)()) Function_Hook;
  53.     hook->h_SubEntry = (ULONG (*)())c_function;
  54.     hook->h_Data = Data;
  55. }
  56.  
  57.  
  58. #endif /* __GNUC__ */
  59.  
  60.  
  61.